package com.gufe.other.config;

import com.gufe.other.interceptor.JwtTokenAdminInterceptor;
import com.gufe.other.interceptor.JwtTokenUserInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/*
 * 配置类，注册web层相关组件
*/

@Configuration
@Slf4j
public class WebMvcConfiguration extends WebMvcConfigurationSupport {

    @Autowired
    private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
    @Autowired
    private JwtTokenUserInterceptor jwtTokenUserInterceptor;

    /*注册自定义拦截器*/
    protected void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注册自定义拦截器...");
        registry.addInterceptor(jwtTokenAdminInterceptor)
                .addPathPatterns("/admin/**")//拦截范围
                .excludePathPatterns("/admin/captcha")
                .excludePathPatterns("/admin/login");//放行范围
                // .excludePathPatterns("/**");//放行所有
        log.info("管理端拦截器注册成功...");

        registry.addInterceptor(jwtTokenUserInterceptor)
                .addPathPatterns("/user/**")//拦截范围
                .excludePathPatterns("/user/user/login");//放行范围
                //.excludePathPatterns("/**");//放行所有
        log.info("用户端拦截器注册成功...");

    }


}
